package com.zh.app.service;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import com.zh.app.dao.LogDao;
import com.zh.app.dao.UserDao;
import com.zh.app.dao.impl.UserDaoImpl;
import com.zh.app.model.Log;
import com.zh.app.model.User;

@Component("userService")
public class UserService {
	// private PlatformTransactionManager platformTransactionManager;
	// public PlatformTransactionManager getPlatformTransactionManager() {
	// return platformTransactionManager;
	// }
	//
	// @Resource(name="txManager")
	// public void setPlatformTransactionManager(
	// PlatformTransactionManager platformTransactionManager) {
	// this.platformTransactionManager = platformTransactionManager;
	// }

	private UserDao userDao;
	private LogDao logDao;

	public LogDao getLogDao() {
		return logDao;
	}

	@Resource(name = "logDao")
	public void setLogDao(LogDao logDao) {
		this.logDao = logDao;
	}

	//@Transactional
	public void add(User u) {
		// TransactionTemplate transactionTemplate = new
		// TransactionTemplate(this.platformTransactionManager);
		// transactionTemplate.execute(new TransactionCallback() {
		//
		// @Override
		// public Object doInTransaction(TransactionStatus status) {
		userDao.save(u);
		Log log = new Log();
		log.setId(99);
		log.setMsg("this is my first message");
		logDao.save(log);
		// return null;
		// }
		// });
	}

	public UserDao getUserDao() {
		return userDao;
	}

	@Resource(name = "userDao")
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
}
